<?php
/**
 * Created by PhpStorm.
 * User: liuwei
 * Date: 2022/12/16
 * Time: 14:19
 */

namespace App\Http\Controllers\Api;

use App\Http\Requests\ApiV2\PointRequest;
use Illuminate\Http\Request;
use App\Services\Member\Models\Family;
use App\Services\Member\Models\Points;



class PointController extends BaseController
{


    public function __construct()
    {


    }

    public function index(Request $request)
    {
        $page = $request->input('page', 1);
        $size = $request->input('size', 20);
        $query =Points::query()
            ->with(['user'])
            ->orderByDesc('id');
        $total = $query->count();
        $problems = $query->forPage($page, $size)->get()->toArray();

        return $this->successData(compact('problems', 'total'));
    }

    public function store(PointRequest $request, Points $point)
    {


        $data = $request->filldata();
        $point->fill($data)->save();
        return $this->success("成功");
    }
    public function edit(Request $request, $id)
    {
        $point =Points::query()->where('id', $id)->firstOrFail()->toArray();
        return $this->successData(compact('point'));
    }

    public function update(PointRequest $request, $id)
    {
        $problem =Points::query()->where('id', $id)->firstOrFail();
        $data = $request->filldata();
        $problem->fill($data)->save();
        return $this->success(__('更新成功'));
    }


    public function delete($id)
    {
        $point =Points::query()->where('id', $id)->firstOrFail();
        $point->delete();
        return $this->success(__('删除成功'));
    }


}